package com.xwt.pattern.iterator;

import java.util.ArrayList;

/**
 * Author:  Steven Xiao
 * Description:定义一个迭代器
 * Date:  2016/3/23
 * Time:  16:38
 */
public class ProjectIterator implements IProjectIterator {
    //所有的项目都放在这个ArrayList中
    private ArrayList<IProject> projectList = new ArrayList<>();

    private int currentItem = 0;

    public ProjectIterator(ArrayList<IProject> projectList) {
        this.projectList = projectList;
    }

    //判断是否还有元素，必须实现
    @Override
    public boolean hasNext() {
        //定义一个返回值
        boolean b = true;
        if ((this.currentItem >= projectList.size()) || this.projectList.get(this.currentItem) == null) {
            b = false;
        }
        return b;
    }

    @Override
    public Object next() {
        return this.projectList.get(this.currentItem++);
    }

}
